<template>
	<uni-section title="您已投票" type="line">
		<uni-card :title="voteDetails.title" :extra="voteDetails.manager.name">
			<text class="uni-body">{{voteDetails.content}}</text>
		</uni-card>
		<uni-card :is-shadow="false">
			<text class="uni-body" v-for="(item,index) in voteOption" >
				<text>{{item.text}}</text><br>
				<text>共{{item.num}}票</text>
				<view class="progress-box">
					<progress 
					:percent="pgList[index]" 
					show-info 
					stroke-width="3" 
					:stroke-width="10" />
				</view>
				<br>
			</text>
		</uni-card>
	</uni-section>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				cover: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/094a9dc0-50c0-11eb-b680-7980c8a877b8.jpg',
				avatar: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/460d46d0-4fcc-11eb-8ff1-d5dcf8779628.png',
				extraIcon:{
					color: '#4cd964',
					size: '22',
					type: 'gear-filled'
				},
				// 基础表单数据
				voteDetails: {
					id:0,
					klassId:0,
					title:'',
					content:'',
					endTime:'',
					startTime:'',
					manager:{},
					radio:'',
					senderId:'',
					status:'',
					voteOption:[],
					voteNum:0
				},
				radioed: 0,
				checkbox: [0],
				voteOption:[],
				pgList:[]
			}
		},
		onLoad(e) {
			this.id=e.id
			this.radio=e.radio
			this.studentId=localStorage.getItem("studentId")
			this.getVoteDetails(this.id)
		},
		methods: {
			getVoteDetails(id){
				this.$myReq({
					url: `/vote/api/getDetails/` + id,
					method: 'get'
				})
				.then((res) => {
					this.voteDetails = res.data
					this.voteOption = res.data.voteOption
					let numSun = 0;
					for (let item1 in this.voteOption) {
						numSun+=(this.voteOption[item1].num)
					}
					for (let item2 in this.voteOption) {
						if(numSun==0){
							this.pgList.push(0)
						}else{
							// console.log((((this.voteOption[item2].num)/numSun)*100).toFixed(2))
							this.pgList.push((((this.voteOption[item2].num)/numSun)*100).toFixed(2))
						}
					}
					console.log(this.pgList)
				})
				.catch((err) => {
					console.log(err)
				})
				
			},
			onClick(e){
				console.log(e)
			},
			actionsClick(text){
				uni.showToast({
					title:text,
					icon:'none'
				})
			}
		}
	}
</script>


<style>
</style>